```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java集合框架：Set接口详解</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8fafc;
            color: #1e293b;
            line-height: 1.6;
        }
        .hero {
            background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
            color: white;
        }
        .code-block {
            background-color: #1e293b;
            color: #e2e8f0;
            border-left: 4px solid #2563eb;
        }
        .feature-card {
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
        }
        .feature-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
        }
        .section-title {
            position: relative;
            padding-bottom: 0.5rem;
        }
        .section-title:after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 3rem;
            height: 3px;
            background: #2563eb;
            border-radius: 3px;
        }
        .highlight {
            background-color: #dbeafe;
            padding: 0.2rem 0.4rem;
            border-radius: 0.25rem;
            font-weight: 500;
        }
    </style>
</head>
<body class="antialiased">
    <!-- Hero Section -->
    <section class="hero py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="flex flex-col items-center text-center">
                <div class="w-20 h-20 bg-white rounded-full flex items-center justify-center mb-6">
                    <i class="fab fa-java text-4xl text-blue-600"></i>
                </div>
                <h1 class="text-4xl md:text-5xl font-bold mb-4 font-serif">Java集合框架：Set接口详解</h1>
                <p class="text-xl md:text-2xl text-blue-100 max-w-3xl leading-relaxed">
                    探索Set接口的精妙设计，掌握高效存储不重复元素的艺术
                </p>
                <div class="mt-8 animate-bounce">
                    <i class="fas fa-chevron-down text-2xl opacity-70"></i>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl px-4 py-12">
        <!-- Introduction -->
        <section class="mb-16">
            <p class="text-lg leading-relaxed mb-8 text-slate-700">
                集合框架提供了丰富的数据结构来存储和操作数据。<span class="highlight">Set</span> 是其中一种集合类型，它用于存储不重复的元素，提供了高效的插入、删除和查找操作。本文将从基础概念到高级应用，全面剖析Java中的Set接口。
            </p>
            
            <!-- Quick Facts -->
            <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-12">
                <div class="bg-white p-6 rounded-xl shadow-sm feature-card">
                    <div class="text-blue-600 text-3xl mb-4">
                        <i class="fas fa-ban"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-2">唯一性保证</h3>
                    <p class="text-slate-600">自动处理重复元素，确保集合中每个元素都是唯一的</p>
                </div>
                <div class="bg-white p-6 rounded-xl shadow-sm feature-card">
                    <div class="text-blue-600 text-3xl mb-4">
                        <i class="fas fa-bolt"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-2">高效操作</h3>
                    <p class="text-slate-600">O(1)或O(log n)时间复杂度的插入、删除和查找</p>
                </div>
                <div class="bg-white p-6 rounded-xl shadow-sm feature-card">
                    <div class="text-blue-600 text-3xl mb-4">
                        <i class="fas fa-project-diagram"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-2">集合运算</h3>
                    <p class="text-slate-600">支持并集、交集、差集等数学集合操作</p>
                </div>
            </div>
        </section>

        <!-- Set Interface Overview -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">1. Set接口概述</h2>
            <div class="bg-white rounded-xl shadow-sm p-6 mb-8">
                <p class="mb-4 text-slate-700">
                    <span class="highlight">Set</span> 是 Java 集合框架中的一种接口，它继承自 <span class="highlight">Collection</span> 接口，表示一组不包含重复元素的集合。<span class="highlight">Set</span> 接口不保证元素的顺序，具体的实现类可能会按照不同的规则来排序。
                </p>
                <div class="mermaid mt-6 mb-4">
                    graph TD
                        A[Collection] --> B[Set]
                        B --> C[HashSet]
                        B --> D[LinkedHashSet]
                        B --> E[TreeSet]
                </div>
                <p class="text-sm text-slate-500 mt-2">
                    * Set接口继承关系图
                </p>
            </div>
        </section>

        <!-- Set Characteristics -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">2. Set接口的特点</h2>
            <div class="bg-white rounded-xl shadow-sm p-6">
                <ul class="space-y-4">
                    <li class="flex items-start">
                        <div class="flex-shrink-0 h-6 w-6 rounded-full bg-blue-100 text-blue-600 flex items-center justify-center mr-3 mt-1">
                            <i class="fas fa-check text-xs"></i>
                        </div>
                        <div>
                            <span class="font-semibold">不允许重复元素：</span> 
                            <span class="text-slate-700">Set中不允许存储重复的元素，即集合中的元素是唯一的。</span>
                        </div>
                    </li>
                    <li class="flex items-start">
                        <div class="flex-shrink-0 h-6 w-6 rounded-full bg-blue-100 text-blue-600 flex items-center justify-center mr-3 mt-1">
                            <i class="fas fa-check text-xs"></i>
                        </div>
                        <div>
                            <span class="font-semibold">无序性：</span> 
                            <span class="text-slate-700">Set接口不保证元素的顺序，具体实现类可能会按照哈希表或树的数据结构来组织元素。</span>
                        </div>
                    </li>
                    <li class="flex items-start">
                        <div class="flex-shrink-0 h-6 w-6 rounded-full bg-blue-100 text-blue-600 flex items-center justify-center mr-3 mt-1">
                            <i class="fas fa-check text-xs"></i>
                        </div>
                        <div>
                            <span class="font-semibold">允许null元素：</span> 
                            <span class="text-slate-700">大多数Set实现类允许存储一个null元素，但不保证所有实现类都支持。</span>
                        </div>
                    </li>
                </ul>
            </div>
        </section>

        <!-- Set Implementations -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">3. Set接口的常见实现类</h2>
            <div class="bg-white rounded-xl shadow-sm overflow-hidden">
                <div class="grid grid-cols-1 md:grid-cols-3 divide-x-0 md:divide-x divide-y md:divide-y-0 divide-slate-200">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="h-10 w-10 rounded-md bg-red-100 text-red-600 flex items-center justify-center mr-3">
                                <i class="fas fa-hashtag"></i>
                            </div>
                            <h3 class="text-xl font-bold">HashSet</h3>
                        </div>
                        <p class="text-slate-700 mb-4">基于哈希表的无序集合，插入、删除、查找操作的时间复杂度均为O(1)。</p>
                        <div class="text-sm bg-slate-50 p-3 rounded">
                            <span class="font-medium text-slate-600">适用场景：</span>
                            <span class="text-slate-500">需要快速操作且不关心顺序</span>
                        </div>
                    </div>
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="h-10 w-10 rounded-md bg-green-100 text-green-600 flex items-center justify-center mr-3">
                                <i class="fas fa-link"></i>
                            </div>
                            <h3 class="text-xl font-bold">LinkedHashSet</h3>
                        </div>
                        <p class="text-slate-700 mb-4">具有可预知迭代顺序的集合，内部使用链表维护元素的插入顺序。</p>
                        <div class="text-sm bg-slate-50 p-3 rounded">
                            <span class="font-medium text-slate-600">适用场景：</span>
                            <span class="text-slate-500">需要记住元素插入顺序</span>
                        </div>
                    </div>
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="h-10 w-10 rounded-md bg-purple-100 text-purple-600 flex items-center justify-center mr-3">
                                <i class="fas fa-tree"></i>
                            </div>
                            <h3 class="text-xl font-bold">TreeSet</h3>
                        </div>
                        <p class="text-slate-700 mb-4">基于红黑树的有序集合，按照元素的自然顺序或者指定的比较器进行排序。</p>
                        <div class="text-sm bg-slate-50 p-3 rounded">
                            <span class="font-medium text-slate-600">适用场景：</span>
                            <span class="text-slate-500">需要元素有序排列</span>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Basic Operations -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">4. Set接口的基本操作</h2>
            <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-sm p-6">
                    <h3 class="text-xl font-bold mb-4 text-blue-600">常用方法</h3>
                    <ul class="space-y-3">
                        <li class="flex items-start">
                            <div class="text-blue-500 mr-2 mt-1">
                                <i class="fas fa-plus-circle"></i>
                            </div>
                            <div>
                                <span class="font-medium">add(E e):</span> 添加元素到集合
                            </div>
                        </li>
                        <li class="flex items-start">
                            <div class="text-blue-500 mr-2 mt-1">
                                <i class="fas fa-minus-circle"></i>
                            </div>
                            <div>
                                <span class="font-medium">remove(Object o):</span> 从集合中移除元素
                            </div>
                        </li>
                        <li class="flex items-start">
                            <div class="text-blue-500 mr-2 mt-1">
                                <i class="fas fa-search"></i>
                            </div>
                            <div>
                                <span class="font-medium">contains(Object o):</span> 检查集合是否包含元素
                            </div>
                        </li>
                        <li class="flex items-start">
                            <div class="text-blue-500 mr-2 mt-1">
                                <i class="fas fa-list"></i>
                            </div>
                            <div>
                                <span class="font-medium">size():</span> 返回集合中元素数量
                            </div>
                        </li>
                        <li class="flex items-start">
                            <div class="text-blue-500 mr-2 mt-1">
                                <i class="fas fa-trash-alt"></i>
                            </div>
                            <div>
                                <span class="font-medium">clear():</span> 清空集合
                            </div>
                        </li>
                    </ul>
                </div>
                <div>
                    <div class="code-block rounded-lg p-6 overflow-x-auto">
                        <pre class="text-sm"><code class="language-java">import java.util.*;

public class SetDemo {
    public static void main(String[] args) {
        // 使用 HashSet 创建 Set 集合
        Set&lt;String&gt; hashSet = new HashSet&lt;&gt;();
        hashSet.add("apple");
        hashSet.add("banana");
        hashSet.add("orange");

        // 使用 LinkedHashSet 创建 Set 集合
        Set&lt;String&gt; linkedHashSet = new LinkedHashSet&lt;&gt;();
        linkedHashSet.add("apple");
        linkedHashSet.add("banana");
        linkedHashSet.add("orange");

        // 使用 TreeSet 创建 Set 集合
        Set&lt;String&gt; treeSet = new TreeSet&lt;&gt;();
        treeSet.add("apple");
        treeSet.add("banana");
        treeSet.add("orange");

        // 遍历 HashSet
        System.out.println("HashSet:");
        for (String fruit : hashSet) {
            System.out.println(fruit);
        }

        // 遍历 LinkedHashSet
        System.out.println("\nLinkedHashSet:");
        for (String fruit : linkedHashSet) {
            System.out.println(fruit);
        }

        // 遍历 TreeSet
        System.out.println("\nTreeSet:");
        for (String fruit : treeSet) {
            System.out.println(fruit);
        }
    }
}</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <!-- Performance Analysis -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">5. 性能分析与适用场景</h2>
            <div class="bg-white rounded-xl shadow-sm overflow-hidden">
                <div class="overflow-x-auto">
                    <table class="min-w-full divide-y divide-slate-200">
                        <thead class="bg-slate-50">
                            <tr>
                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-slate-500 uppercase tracking-wider">实现类</th>
                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-slate-500 uppercase tracking-wider">插入/删除/查找</th>
                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-slate-500 uppercase tracking-wider">是否有序</th>
                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-slate-500 uppercase tracking-wider">线程安全</th>
                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-slate-500 uppercase tracking-wider">适用场景</th>
                            </tr>
                        </thead>
                        <tbody class="bg-white divide-y divide-slate-200">
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap font-medium text-slate-900">HashSet</td>
                                <td class="px-6 py-4 whitespace-nowrap text-slate-500">O(1)</td>
                                <td class="px-6 py-4 whitespace-nowrap text-slate-500">无序</td>
                                <td class="px-6 py-4 whitespace-nowrap text-slate-500">否</td>
                                <td class="px-6 py-4 whitespace-nowrap text-slate-500">快速操作，不关心顺序</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap font-medium text-slate-900">LinkedHashSet</td>
                                <td class="px-6 py-4 whitespace-nowrap text-slate-500">O(1)</td>
                                <td class="px-6 py-4 whitespace-nowrap text-slate-500">插入顺序</td>
                                <td class="px-6 py-4 whitespace-nowrap text-slate-500">否</td>
                                <td class="px-6 py-4 whitespace-nowrap text-slate-500">需要记住插入顺序</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap font-medium text-slate-900">TreeSet</td>
                                <td class="px-6 py-4 whitespace-nowrap text-slate-500">O(log n)</td>
                                <td class="px-6 py-4 whitespace-nowrap text-slate-500">自然/比较器顺序</td>
                                <td class="px-6 py-4 whitespace-nowrap text-slate-500">否</td>
                                <td class="px-6 py-4 whitespace-nowrap text-slate-500">需要有序遍历</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </section>

        <!-- Advanced Operations -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">6. Set接口的高级操作</h2>
            <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
                <div>
                    <h3 class="text-xl font-bold mb-4 text-blue-600">集合运算</h3>
                    <div class="code-block rounded-lg p-6 overflow-x-auto mb-6">
                        <pre class="text-sm"><code class="language-java">Set&lt;Integer&gt; set1 = new HashSet&lt;&gt;(Arrays.asList(1, 2, 3, 4));
Set&lt;Integer&gt; set2 = new HashSet&lt;&gt;(Arrays.asList(3, 4, 5, 6));

// 求交集
Set&lt;Integer&gt; intersection = new HashSet&lt;&gt;(set1);
intersection.retainAll(set2); // intersection = {3, 4}

// 求并集
Set&lt;Integer&gt; union = new HashSet&lt;&gt;(set1);
union.addAll(set2); // union = {1, 2, 3, 4, 5, 6}

// 求差集
Set&lt;Integer&gt; difference = new HashSet&lt;&gt;(set1);
difference.removeAll(set2); // difference = {1, 2}</code></pre>
                    </div>
                </div>
                <div>
                    <h3 class="text-xl font-bold mb-4 text-blue-600">去重操作</h3>
                    <div class="code-block rounded-lg p-6 overflow-x-auto">
                        <pre class="text-sm"><code class="language-java">// 从列表中去除重复元素
List&lt;String&gt; list = Arrays.asList("apple", "banana", 
                   "apple", "orange", "banana");
                   
Set&lt;String&gt; uniqueSet = new HashSet&lt;&gt;(list); 
// uniqueSet = {"apple", "banana", "orange"}

// 使用Stream API去重
List&lt;String&gt; distinctList = list.stream()
    .distinct()
    .collect(Collectors.toList());</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <!-- Practical Applications -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">7. Set接口的实际应用</h2>
            <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
                <div class="bg-white rounded-xl shadow-sm p-6">
                    <div class="text-red-500 text-2xl mb-3">
                        <i class="fas fa-filter"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-2">数据去重</h3>
                    <p class="text-slate-700">利用Set的特性快速去除列表中的重复元素，保持数据唯一性。</p>
                </div>
                <div class="bg-white rounded-xl shadow-sm p-6">
                    <div class="text-green-500 text-2xl mb-3">
                        <i class="fas fa-calculator"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-2">集合运算</h3>
                    <p class="text-slate-700">进行数学集合运算，如求交集、并集、差集等。</p>
                </div>
                <div class="bg-white rounded-xl shadow-sm p-6">
                    <div class="text-purple-500 text-2xl mb-3">
                        <i class="fas fa-tags"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-2">标签系统</h3>
                    <p class="text-slate-700">存储和操作不重复的标签或分类数据。</p>
                </div>
            </div>
        </section>

        <!-- Stream API Integration -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">8. Set接口与Stream API的结合使用</h2>
            <div class="bg-white rounded-xl shadow-sm p-6">
                <p class="mb-4 text-slate-700">
                    Java 8引入的Stream API可以与Set无缝集成，进行复杂的数据处理和转换操作。以下是一个使用Stream处理Set的示例：
                </p>
                <div class="code-block rounded-lg p-6 overflow-x-auto mt-4">
                    <pre class="text-sm"><code class="language-java">Set&lt;String&gt; fruits = new HashSet&lt;&gt;(
    Arrays.asList("apple", "banana", "orange", "pear"));

// 使用Stream进行过滤和处理
Set&lt;String&gt; filteredFruits = fruits.stream()
    .filter(fruit -> fruit.startsWith("a"))
    .map(String::toUpperCase)
    .collect(Collectors.toSet()); 
    // filteredFruits = {"APPLE"}

// 转换为其他集合类型
List&lt;String&gt; sortedFruits = fruits.stream()
    .sorted()
    .collect(Collectors.toList());
    
// 并行处理提高性能
Set&lt;Integer&gt; lengths = fruits.stream()
    .parallel()
    .map(String::length)
    .collect(Collectors.toSet());</code></pre>
                </div>
            </div>
        </section>

        <!-- Key Takeaways -->
        <section class="bg-blue-50 rounded-xl p-8 mb-16">
            <h2 class="text-2xl font-bold mb-6 text-blue-800 flex items-center">
                <i class="fas fa-lightbulb mr-3"></i> 关键要点总结
            </h2>
            <ul class="space-y-3">
                <li class="flex items-start">
                    <div class="flex-shrink-0 h-5 w-5 text-blue-500 mt-1 mr-3">
                        <i class="fas fa-circle"></i>
                    </div>
                    <div class="text-slate-700">Set接口用于存储不重复元素，实现类包括HashSet、LinkedHashSet和TreeSet</div>
                </li>
                <li class="flex items-start">
                    <div class="flex-shrink-0 h-5 w-5 text-blue-500 mt-1 mr-3">
                        <i class="fas fa-circle"></i>
                    </div>
                    <div class="text-slate-700">根据需求选择实现类：HashSet(快速)、LinkedHashSet(保持顺序)、TreeSet(排序)</div>
                </li>
                <li class="flex items-start">
                    <div class="flex-shrink-0 h-5 w-5 text-blue-500 mt-1 mr-3">
                        <i class="fas fa-circle"></i>
                    </div>
                    <div class="text-slate-700">自定义对象作为Set元素时，必须正确重写equals()和hashCode()方法</div>
                </li>
                <li class="flex items-start">
                    <div class="flex-shrink-0 h-5 w-5 text-blue-500 mt-1 mr-3">
                        <i class="fas fa-circle"></i>
                    </div>
                    <div class="text-slate-700">Set不是线程安全的，多线程环境下需要外部同步或使用并发集合</div>
                </li>
                <li class="flex items-start">
                    <div class="flex-shrink-0 h-5 w-5 text-blue-500 mt-1 mr-3">
                        <i class="fas fa-circle"></i>
                    </div>
                    <div class="text-slate-700">结合Stream API可以高效地进行数据过滤、转换和聚合操作</div>
                </li>
            </ul>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-slate-900 text-white py-8">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="flex flex-col items-center text-center">
                <h3 class="text-lg font-medium mb-2">技术小馆</h3>
                <a href="http://www.yuque.com/jtostring" class="text-blue-300 hover:text-blue-100 transition-colors duration-200">
                    <i class="fas fa-external-link-alt mr-1"></i> http://www.yuque.com/jtostring
                </a>
            </div>
        </div>
    </footer>

    <script>
        // Initialize Mermaid
        document.addEventListener('DOMContentLoaded', function() {
            mermaid.initialize({
                startOnLoad: true,
                theme: 'default',
                flowchart: {
                    useMaxWidth: true,
                    htmlLabels: true,
                    curve: 'basis'
                }
            });
        });
    </script>
</body>
</html>
```